<template>
	<ContentWrap>
		<el-space wrap>
            <el-input v-model="filters.orderId" style="width: 20%;" placeholder="订单编号" clearable title="支持>、<、 >=、<=、!=、*字符*、$IS NULL、$IN 1,2,3、$between 1,5等操作符"/>
			<el-input v-model="filters.moduleId" style="width: 20%;" placeholder="模块编号" clearable title="支持>、<、 >=、<=、!=、*字符*、$IS NULL、$IN 1,2,3、$between 1,5等操作符"/>
 			<el-button v-loading="load.list" :disabled="load.list==true" @click="searchTableDatas()" icon="search" type="primary">查询</el-button>

		</el-space>
        <template #header>
		<el-space wrap> 
            <mdp-hi-query :column-configs="columnConfigs" v-model="hiQueryParams" @change="onHiQueryParamsChange"/>
            <el-button icon="zoom-out" @click="searchReset()" title="重置查询条件"/>
            
            <el-button icon="download" @click="export2Excel()" title="导出" />
            <mdp-table-configs :column-configs="columnConfigs" v-model="checkedColumns"/>
            <span  v-if="currOpType=='mng'">
                <el-button :disabled="disBtn('delBtn') || !checkBtnQx('delBtn',menuDefId) || this.sels.length===0 || load.del==true" type="danger" plain v-loading="load.del" @click="batchDel" icon="delete"/>

                <el-button :disabled="disBtn('addBtn') || !checkBtnQx('addBtn',menuDefId) " type="primary" plain @click="openForm({parentOpType:currOpType,subOpType:'add',formData:addForm,title:'新增'})" icon="plus"/>
            </span>
            <span  v-else-if="currOpType=='select' &&  this.multiple==true">
                <el-button :disabled="disBtn('selectBtn') || this.sels.length===0" type="primary" @click="selectListConfirm" icon="check"/>
            </span>
		</el-space>
        </template>
    </ContentWrap> 
			<!--列表 MoOrderModule 订单与模块关系表-->
			<el-table v-adaptive :ref="refId+'Table'"  :data="tableDatas" @sort-change="sortChange" highlight-current-row v-loading="load.list" border @selection-change="selsChange" @row-click="rowClick" style="width: 100%;">
				<el-table-column  type="selection" width="55" show-overflow-tooltip fixed="left" v-if="currOpType=='mng' || this.multiple==true"/>
				<el-table-column sortable type="index" width="55" show-overflow-tooltip  fixed="left"/>
				<el-table-column prop="orderId" label="订单编号" min-width="120" show-overflow-tooltip  fixed="left" col-type="String" v-if="showCol('orderId')"/>
				<el-table-column prop="moduleId" label="模块编号" min-width="120" show-overflow-tooltip  fixed="left" col-type="String" v-if="showCol('moduleId')"/>
				<el-table-column prop="name"  label="模块名称" min-width="120" show-overflow-tooltip col-type="String" v-if="showCol('name')">
				    <template #default="scope">
                            <mdp-input show-style="tag" v-model="scope.row.name" :maxlength="255" @change="editSomeFields(scope.row,'name',$event)" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="fee"  label="模块费用" min-width="120" show-overflow-tooltip col-type="BigDecimal" v-if="showCol('fee')">
				    <template #default="scope">
                            <mdp-input show-style="tag" v-model="scope.row.fee" :maxlength="10" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="billMode"  label="计费模式" min-width="120" show-overflow-tooltip col-type="String" v-if="showCol('billMode')">
				    <template #default="scope">
                            <mdp-select @click="rowClick(scope.row)" item-code="moduleBillMode" show-style="tag" v-model="scope.row.billMode" :maxlength="1" @change="editSomeFields(scope.row,'billMode',$event)" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="uniFee"  label="人均费用" min-width="120" show-overflow-tooltip col-type="BigDecimal" v-if="showCol('uniFee')">
				    <template #default="scope">
                            <mdp-input show-style="tag" v-model="scope.row.uniFee" :maxlength="10" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="mcate"  label="分类" min-width="120" show-overflow-tooltip col-type="String" v-if="showCol('mcate')">
				    <template #default="scope">
                            <mdp-select @click="rowClick(scope.row)" item-code="mcate" show-style="tag" v-model="scope.row.mcate" :maxlength="50" @change="editSomeFields(scope.row,'mcate',$event)" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="feeDesc"  label="费用解释" min-width="120" show-overflow-tooltip col-type="String" v-if="showCol('feeDesc')">
				    <template #default="scope">
                            <mdp-input show-style="tag" v-model="scope.row.feeDesc" :maxlength="255" @change="editSomeFields(scope.row,'feeDesc',$event)" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="udisRate"  label="人数折算比例" min-width="120" show-overflow-tooltip col-type="Integer" v-if="showCol('udisRate')">
				    <template #default="scope">
                            <mdp-number show-style="tag" v-model="scope.row.udisRate" :precision="0" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="udis"  label="是否折算人数" min-width="120" show-overflow-tooltip col-type="String" v-if="showCol('udis')">
				    <template #default="scope">
                            <mdp-input show-style="tag" v-model="scope.row.udis" :maxlength="1" @change="editSomeFields(scope.row,'udis',$event)" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="musers"  label="购买人数" min-width="120" show-overflow-tooltip col-type="Integer" v-if="showCol('musers')">
				    <template #default="scope">
                            <mdp-number show-style="tag" v-model="scope.row.musers" :precision="0" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="orginFee"  label="原始总费用" min-width="120" show-overflow-tooltip col-type="BigDecimal" v-if="showCol('orginFee')">
				    <template #default="scope">
                            <mdp-input show-style="tag" v-model="scope.row.orginFee" :maxlength="10" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="finalFee"  label="最终总费用" min-width="120" show-overflow-tooltip col-type="BigDecimal" v-if="showCol('finalFee')">
				    <template #default="scope">
                            <mdp-input show-style="tag" v-model="scope.row.finalFee" :maxlength="10" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="disRate"  label="订单折扣率" min-width="120" show-overflow-tooltip col-type="Integer" v-if="showCol('disRate')">
				    <template #default="scope">
                            <mdp-number show-style="tag" v-model="scope.row.disRate" :precision="0" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="days"  label="购买天数" min-width="120" show-overflow-tooltip col-type="Integer" v-if="showCol('days')">
				    <template #default="scope">
                            <mdp-number show-style="tag" v-model="scope.row.days" :precision="0" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="ucheck"  label="是否控制总人数" min-width="120" show-overflow-tooltip col-type="String" v-if="showCol('ucheck')">
				    <template #default="scope">
                            <mdp-input show-style="tag" v-model="scope.row.ucheck" :maxlength="1" @change="editSomeFields(scope.row,'ucheck',$event)" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="ousers"  label="企业总人数" min-width="120" show-overflow-tooltip col-type="Integer" v-if="showCol('ousers')">
				    <template #default="scope">
                            <mdp-number show-style="tag" v-model="scope.row.ousers" :precision="0" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column prop="ver"  label="购买的版本" min-width="120" show-overflow-tooltip col-type="String" v-if="showCol('ver')">
				    <template #default="scope">
                            <mdp-select @click="rowClick(scope.row)" item-code="menuSupVers" show-style="tag" v-model="scope.row.ver" :maxlength="1" @change="editSomeFields(scope.row,'ver',$event)" :disabled="disField"/>
				    </template>
				</el-table-column>
                
                
				<el-table-column prop="logoUrl"  label="logo地址" min-width="120" show-overflow-tooltip col-type="String" v-if="showCol('logoUrl')">
				    <template #default="scope">
                            <mdp-input show-style="tag" v-model="scope.row.logoUrl" :maxlength="255" @change="editSomeFields(scope.row,'logoUrl',$event)" :disabled="disField"/>
				    </template>
				</el-table-column>
				<el-table-column label="操作" :width="currOpType=='mng'?180:200" fixed="right"> 
				    <template #default="scope" v-if="currOpType=='mng'"  >
				        <el-button :disabled="disBtn('editBtn') || !checkBtnQx('editBtn',menuDefId) " type="primary" @click="openForm({parentOpType:currOpType,subOpType:'edit',formData:scope.row,title:'修改'})" icon="edit" title="修改一条数据"/>
 				        <el-button :disabled="disBtn('delBtn') || !checkBtnQx('delBtn',menuDefId) " type="danger" @click="handleDel(scope.row,scope.$index)" icon="delete"  title="删除一条数据"/>
				    </template>

				    <template #default="scope" v-else-if="currOpType=='list'" >
				        <el-button   type="primary" @click="openForm({parentOpType:currOpType,subOpType:'detail',formData:scope.row})" icon="view"/>
 				    </template>

				    <template #default="scope" v-else-if="currOpType=='select' && this.multiple!=true" >
				        <el-button   type="primary" @click="selectConfirm(scope.row)" icon="check"/>
 				    </template>
				</el-table-column>
			</el-table> 
			<el-pagination class="padding-top"
				layout="slot,total, sizes, prev, next,pager,jumper"
				@current-change="handleCurrentChange"
				@size-change="handleSizeChange"
				:page-sizes="[10,20, 50, 100, 500]"
				:current-page="pageInfo.pageNum"
				:page-size="pageInfo.pageSize"
				:total="pageInfo.total"
			/> 
			<!--新增修改明细 MoOrderModule 订单与模块关系表界面-->
            <mdp-dialog :ref="refId+'FormDialog'">
                <template #default="{visible,data}">
                     <mo-order-module-form :ref="refId+'Form'" :visible="visible" :parent-op-type="currOpType" :sub-op-type="data.subOpType" :form-data="data.formData" @close="onFormClose" @submit="afterFormSubmit" @fields-change="afterEditSomeFields"/>
                </template>
            </mdp-dialog> 
</template>

<script>

import util from '@/components/mdp-ui/js/util';//全局公共库
import { MdpTableMixin } from '@/components/mdp-ui/mixin/MdpTableMixin.js';
import config from '@/api/mdp_pub/mdp_config';//全局公共库
import * as MoOrderModuleApi from '@/api/mdp/mo/moOrderModule';
import  MoOrderModuleForm from './Form.vue';//新增修改明细界面
import { mapState } from 'pinia'
import { useUserStore } from '@/store/modules/user'

export default {
    name:'moOrderModuleMng',
    mixins:[MdpTableMixin],
    components: {
        MoOrderModuleForm,
    },
    props:{
        moOrder:{
            type:Object,
            default:null,
        }
    },
    computed: {
    },
    watch:{
    },
    data() {
        return {
            menuDefId:'',//menu_def.id 菜单表菜单编号，用于按钮权限判断
            menuDefName:'订单与模块关系表',//menu_def.name 功能名称，用于导出excel等文件名
            refId:'moOrderModule',//引用编号，<table :ref="refId+'Table'"> <form :ref="refId+'Form'">
            pkNames:["orderId", "moduleId"],//表格主键的java属性名称，驼峰命名，默认为id,支持多主键
            
            filters:{//查询参数

            },
            defaultFilters:{//默认查询参数,第一次打开界面的时候用到，恢复默认值的时候用到

            },

            defaultCheckColumnNum:8,//默认展示的表格列数，前8列

            //增删改查(含批量)接口
            apis:{
                list: MoOrderModuleApi.listMoOrderModule,
                add: MoOrderModuleApi.addMoOrderModule,
                del: MoOrderModuleApi.delMoOrderModule,
                edit: MoOrderModuleApi.editMoOrderModule,
                editSomeFields: MoOrderModuleApi.editSomeFieldsMoOrderModule,
                batchAdd: MoOrderModuleApi.batchAddMoOrderModule,
                batchDel: MoOrderModuleApi.batchDelMoOrderModule,
                batchEdit: MoOrderModuleApi.batchEditMoOrderModule,
            }
        }
    },
    methods: {
         //页面初始化需要配置的特殊逻辑写这里
          initCurrData(){
             this.searchTableDatas();
          },

          /**
           * 检查参数是否满足调用后台接口的条件
           *
           * @param params 提交给后台的参数池,map类型
           * @returns true / false
           */
          preQueryParamCheck(params){
            if(this.moOrder){
                params.orderId=this.moOrder.id
            }
              return true;
          },

          //页面数据加载完后需要对数据进行加工处理的
          afterList(res,isOk,apiName){

          },

          /**
           * 对修改的字段进行判断，返回false ,将取消更新数据库
           * @param {*} row 当前选中的行
           * @param {*} fieldName 修改的字段名
           * @param {*} $event 修改后的值
           * @param {*} params 将要提交服务器的参数
           * @returns true/false 返回false ,将取消更新数据库
           */
          editSomeFieldsCheck(row,fieldName,$event,params){
              if(this.currOpType=='add'||this.currOpType=='detail'){
                  return false;
              }
              params[fieldName]=$event
              return true;
          },

         /**
          * 打开某个子页面
          */
        openForm(res){
            let {parentOpType,formRefId,subOpType,formData} = res
            if(!formRefId){
                formRefId=this.getRefId()+"FormDialog"
            }
            if(!parentOpType){
                parentOpType=this.currOpType
            }
            var form=this.$refs[formRefId]
            if(form){
                res.parentOpType=parentOpType
                res.formRefId=formRefId
                form.open(res);
            }else{

            }

        },
    },
    mounted() {

    }
}

</script>

<style scoped>
</style>